package com.kaluli.project.service;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.kaluli.project.domain.entity.AdminUser;
import com.kaluli.project.domain.entity.CpsUserVO;
import com.kaluli.project.domain.entity.EntityConverter;
import com.kaluli.project.domain.entity.KllMq;
import com.kaluli.project.domain.entity.KllMqBak;
import com.kaluli.project.domain.entity.KllOptlog;
import com.kaluli.project.domain.entity.KllOptlogBak;
import com.kaluli.project.domain.entity.KllUser;
import com.kaluli.project.domain.entity.LipinkaVO;
import com.kaluli.project.domain.entity.StockVO;
import com.kaluli.project.domain.repository.KllAdminUserRepository;
import com.kaluli.project.domain.repository.KllLipinkaRepository;
import com.kaluli.project.domain.repository.KllMqBakRepository;
import com.kaluli.project.domain.repository.KllMqRepository;
import com.kaluli.project.domain.repository.KllOptlogBakRepository;
import com.kaluli.project.domain.repository.KllOptlogRepository;
import com.kaluli.project.domain.repository.KllStockRepository;
import com.kaluli.project.domain.repository.KllUserRepository;

import freemarker.template.Template;

@Service
@Configuration
@Component
@PropertySource({ "classpath:mail.properties","classpath:thridsystem.properties" })
public class KllLipinkaService {

	@Autowired
	private Environment env;


	@Autowired
	private KllLipinkaRepository kllLipinkaRepository;
	
	@Autowired
	private KllUserRepository kllUserRepository;
	
	@Autowired
	private KllAdminUserRepository kllAdminUserRepository;

	static Logger log = Logger.getLogger(KllLipinkaService.class);
	
	
	/**
	 * 定时发送新用户渠道数据	
	 * 
	 * @throws Exception
	 */
	public LipinkaVO findLipinka(String orderNumber) throws Exception {
		LipinkaVO vo = null;
		List<LipinkaVO> list = kllLipinkaRepository.findLipinka(orderNumber);
		if(list != null && list.size()>0){
			vo = list.get(0);
			//翻译申请人姓名;审核人姓名
			AdminUser apply = kllAdminUserRepository.findByHupuId(vo.getApply());
			AdminUser verify =kllAdminUserRepository.findByHupuId(vo.getVerify());
			//翻译金额限制
			String limit = vo.getCardLimit();
			if(StringUtils.isBlank(limit)){
				limit = "无限制";
			}else{
				//order_money=100
				String amount = limit.substring(12);
				limit = "满"+amount+"元使用";
			}
			if(apply != null ){
				vo.setApply(apply.getUserName());
			}
			if(verify != null){
				vo.setVerify(verify.getUserName());
			}
			vo.setCardLimit(limit);
			
		}
		return vo;
		
	}
	
	public static void main(String[] args) {
		String str = "order_money=100";
		str = str.substring(12);
		System.out.println(str);
	}
	


}
